<extend name="Public/base" />
<block name="title1">主页</block>
<block name="css"></block>
<block name="main1"><div style="width:1000px;height:340px">
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	
</head>
<body>


<div id="uid" style="display:none"><{$uid}></div>

<input type="text" value="0" name="count">

<input type="button" name="load" value="load">



<div id="list" style="border:1px solid red;width:100px"></div>

<div id="content"  style="display:none">


</div>



	





	



<script>

$('[name="load"]').click(function(){
    
	var count = $('[name="count"]').val();
	$.get('<{:U("queryadmin")}>',{count:count},function(data){

		$('[name="count"]').val(data.count);
		if(data.success){
			$('[name="load"]').click();
				var html = ''; 
				var b=data.rows.uid;
				var a=new Array();
             $('.obj').each(function(k,v){
		     a.push($(v).text());
                  })
				var result= $.inArray(b,a);
                 //console.log(a);
				// console.log(b);
				//console.log(result);
				if(result<0){
html += '<div style="border:1px;color:red;" id="user'+data.rows.uid+'" class="obj" data-cid="'+data.rows.cid+'" data-uid="'+data.rows.uid+'" >'+data.rows.uid+'</div>';
			/*$(data.rows).map(function(k,v){
				html += '<div style="border:1px;" id="user'+v.cid+'" class="obj" data-cid="'+v.cid+'" data-uid="'+v.uid+'" >'+v.uid+'</div>';
			});*/
			$('#list').append(html);
				}else{
				$("#user"+b).css('color','blue');
				}
	 


		}else{
			$('[name="load"]').click();
		}		

	},'json');

});
$('[name="load"]').click();
$(document).on('click','.obj',function(){
	$(this).css('color','red');
//$('.obj').mouseover(function(){
	cid=$(this).attr('data-cid');
	uid=$(this).attr('data-uid');
	//console.log(uid);
	
       
       var html = '<div id="con" style="border:1px solid red;height:400px"><div id="resid"></div><input type="text" name="content"><input type="submit" name="send" value="发送"><input type="text" value="0" class="count"><input type="button" class="load" value="load"></div>'; 
	   $('#content').after(html);
	   $('#resid').text(uid);
        $('.load').click();
})


$(document).on('click','[name="send"]',function(){
//$('[name="send"]').click(function(){
	//var content = $('[name="content"]').val();
	var uid = $('#uid').text();
	//var resid = $('#resid').text();

 
 var resid=$(this).prev().prev().text();
 var content=$(this).prev().val();
$(this).prev().val('');
 var pa=$(this).parent();
	//$('[name="content"]').val('');

$.post('<{:U("add")}>',{content:content,uid:uid,resid:resid},function(data){
	  var html = ''; 
                 html += '<p>'+data.content+'</p>';

			$(pa).append(html);
	  
	},'json');

});

$(document).on('click','.load',function(){
    var uid = $(this).prev().prev().prev().prev().text();
	var load=$(this);
    var pare=$(this).parent();
	var count = $(this).prev().val();
	var counts=$(this).prev();
	console.log(uid);
	//console.log(count);
	$.get('<{:U("querys")}>',{count:count,uid:uid},function(data){
         
		$(counts).val(data.count);
		console.log(load);
		if(data.success){
           
			
				var html = ''; 
			$(data.rows).map(function(k,v){
				html += '<span><p style="float:right">'+v.content+'</p></span>'
			});

			$(pare).append(html);
           $(load).click();
		}else{
			$(load).click();
		}		

	},'json');

});
//$(document).on('click','.load');






</script>
	
</body>
</html>
</block>